Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
18 | function dark(state, format, visibility, upgrade, data, util) { |
||
19 | let ct = this; |
||
20 | ct.state = state; |
||
21 | ct.data = data; |
||
22 | ct.util = util; |
||
23 | ct.format = format; |
||
24 | ct.cache = {breakdown:{}}; |
||
25 | |||
26 | ct.update = function(player) { |
||
27 | refresh(player); |
||
28 | }; |
||
29 | |||
30 | /* Refreshes the values in the cache */ |
||
31 | function refresh(player){ |
||
32 | ct.cache.breakdown = {}; |
||
33 | for (let element in data.elements) { |
||
34 | let exotic = data.elements[element].exotic; |
||
35 | if (!player.resources[exotic].unlocked || !player.statistics.dark_run[exotic]) { |
||
36 | continue; |
||
37 | } |
||
38 | let number = player.statistics.dark_run[exotic]; |
||
39 | let darkProduction = Math.pow(Math.E,(-0.5+Math.sqrt(0.25+0.8686*Math.log(number/100)))/1.4427) || 0; |
||
40 | ct.cache.breakdown[exotic] = Math.round(Math.max(0, darkProduction)); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | ct.darkProduction = function() { |
||
45 | let production = 0; |
||
46 | for (let resource in ct.cache.breakdown) { |
||
47 | production += ct.cache.breakdown[resource]; |
||
48 | } |
||
49 | |||
50 | return production; |
||
51 | }; |
||
52 | |||
53 | ct.darkPrestige = function() { |
||
54 | let production = ct.darkProduction(); |
||
55 | |||
56 | util.addResource(state.player, 'all_time', 'dark_matter', production); |
||
57 | |||
58 | for(let key in data.elements){ |
||
59 | let element = data.elements[key]; |
||
60 | state.player.resources[element.exotic].number = 0; |
||
61 | if(!state.player.exotic_upgrades[key]){ |
||
62 | continue; |
||
63 | } |
||
64 | for(let up in data.exotic_upgrades){ |
||
65 | state.player.exotic_upgrades[key][up] = false; |
||
66 | } |
||
67 | } |
||
68 | for(let slot of state.player.element_slots){ |
||
69 | if(!slot){ |
||
70 | continue; |
||
71 | } |
||
72 | upgrade.resetElement(state.player, slot.element); |
||
73 | } |
||
74 | |||
75 | for(let i in state.player.element_slots){ |
||
76 | state.player.element_slots[i] = null; |
||
77 | } |
||
78 | state.player.statistics.exotic_run = {}; |
||
79 | state.player.statistics.dark_run = {}; |
||
80 | }; |
||
81 | |||
82 | ct.buyDarkUpgrade = function(name) { |
||
83 | let upgrades = state.player.dark_upgrades; |
||
84 | let price = data.dark_upgrades[name].price; |
||
85 | let currency = 'dark_matter'; |
||
86 | upgrade.buyUpgrade(state.player, |
||
87 | upgrades, |
||
88 | data.dark_upgrades[name], |
||
89 | name, |
||
90 | price, |
||
91 | currency); |
||
92 | }; |
||
93 | |||
94 | ct.visibleDarkUpgrades = function() { |
||
95 | return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0); |
||
96 | }; |
||
97 | |||
98 | // here we receive not the name of the element, but the index in the element_slots |
||
99 | function isDarkUpgradeVisible(name, index) { |
||
100 | return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name]); |
||
101 | } |
||
102 | |||
103 | state.registerUpdate('dark', ct.update); |
||
104 | refresh(state.player); |
||
105 | } |
||
106 |